#include "Cylinder.h"
#include "Scene.h"

ConcreteElementLoader<Cylinder> *Cylinder::loader = new ConcreteElementLoader<Cylinder>();

Cylinder::Cylinder(TiXmlElement *elem) { // TODO IMPLEMENT EXCEPTIONS
	if( elem != NULL ) {
		if( elem->QueryFloatAttribute("base", &base) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("top", &top) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("height", &height) == TIXML_SUCCESS &&
			elem->QueryIntAttribute("slices", &slices) == TIXML_SUCCESS &&
			elem->QueryIntAttribute("stacks", &stacks) == TIXML_SUCCESS ) {	
			#ifdef DEBUG
				printf("Cylinder read: base = %0.1f, top = %0.1f, height = %0.1f, slices = %d, stacks = %d\n", 
					base, top, height, slices, stacks );
			#endif
		}
	}
}

void Cylinder::displayElement() {

		// Cylinder issue here
		gluCylinder(Scene::glQ,
					base,
					top,
					height,
					slices,
					stacks);

		// Z=0 disk
		glPushMatrix();
			glRotated(180 , 0, 0, 1);
			gluDisk(Scene::glQ, 
						0,
						base, 
						slices,
						1); 
		glPopMatrix();

		// Z=Height disk
		glPushMatrix();
			glTranslated(0, 0,  height);
			glRotated(180 , 0, 0, 1);
			gluDisk(Scene::glQ, 
						0,
						top, 
						slices,
						1);
		glPopMatrix();

}